package dao;

import java.util.*;

import org.hibernate.Session;

import entity.*;

public class ProfessorDAO implements DAO<Professor> {
	public Professor load(final long id) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Professor professor = (Professor) session.load(Professor.class, id);
		return professor;
	}

	public List<Professor> loadAll() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		List<Professor> result = session.createQuery(
				"SELECT p FROM Professor p").list();
		return result;
	}

	public void persist(final Professor professor) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.saveOrUpdate(professor);
	}

	public void update(final Professor professor) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.saveOrUpdate(professor);
	}

	public void delete(final long id) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Professor professor = (Professor) session.load(Professor.class, id);
		session.delete(professor);
	}
}
